// pages/store/store.js
import { Store } from '../../model/store.js';
var store = new Store();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_id: '',
    hidden: false,
    start_date: '请选择',
    end_date: '请选择',
    sale: 0,
    income: 0,
    volume: 0,
    new_user: 0,
    fission: 0,
    date: '',
    store: [],
    show: false,
    minDate: new Date().getTime() - (86400000*31*3),
    maxDate: new Date().getTime(),
    sum: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAllNumList()
  },

  /**
   * 获取全部记录
   */
  getAllNumList(){
    wx.showLoading({
      title: '加载中',
    });
    var start_date = ''
    if (this.data.start_date != '请选择') {
      start_date = this.data.start_date
    }
    var end_date = ''
    if (this.data.end_date != '请选择') {
      end_date = this.data.end_date
    }
    store.getAllNumList({ start_time: start_date, end_time: end_date},(res)=>{
      var sum = 0;
      res.forEach((item)=>{
        sum += Number(item.order_price)
      })
        this.setData({
          store: res,
          sum: sum,
        })
      wx.hideLoading();
    })
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  },

  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      show: false,
      start_date: this.formatDate(start),
      end_date: this.formatDate(end)
    });
  },
  openWin(event) {
    wx.navigateTo({
      url: 'store_user_order?store_id=' + event.currentTarget.id + '&store_name=' + event.currentTarget.dataset.name,
    })
  }
})